import { createSlice } from "@reduxjs/toolkit";

const userStore=createSlice({
    name:'userSlice',
    initialState:{
        token:sessionStorage.getItem('token')||null,
        menuList:[]
    },
    reducers:{
        setToken(state,action){
            state.token=action.payload
            sessionStorage.setItem('token',action.payload)
        },
        deleteToken(state){
            state.token=null
            sessionStorage.removeItem('token')
        },
        setMenuList(state,action){
            state.menuList=action.payload
        }
    }
})

const userReducer=userStore.reducer;
export const {setToken,deleteToken,setMenuList}=userStore.actions
export default userReducer
